/*
package com.lld.im.service.utils;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ecode.imecode.pack.MessagePack;
import com.lld.im.common.enums.ConnectStatusEnum;
import com.lld.im.common.enums.commond.Commend;
import com.lld.im.common.model.ClientInfo;
import com.lld.im.common.model.UserSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

*/
/**
 * 消息发送 通过mq 发送消息到tcp层 实现多端数据同步
 *//*

@Component
@Slf4j
public class MessageSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RedisUserSessionUtils redisUserSessionUtils;


    public boolean sendMsg(String data, UserSession userSession) {
        try {
            rabbitTemplate.convertAndSend("", userSession.getBrokerId(), JSONObject.toJSONString(data));
            log.info("消息发送 === {}", data);
            return true;
        } catch (Exception e) {
            log.error("消息发送失败:{}", e.getMessage());
            return false;
        }
    }

    */
/**
     * 对数据进行包装 指定数据包路由信息
     *
     * @param toUserId
     * @param commend
     * @param userSession 发送方信息
     * @return
     *//*

    public boolean sendPack(String toUserId, Commend commend, Object data,
                            UserSession userSession) {
        MessagePack messagePack = new MessagePack();
        messagePack.setToAppId(userSession.getAppId());
        messagePack.setToUserId(toUserId);
        messagePack.setCommand(commend.getCommend());
        messagePack.setToClientType(userSession.getClientType().toString());
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(data));
        messagePack.setData(jsonObject);
        return sendMsg(JSONObject.toJSONString(messagePack), userSession);
    }

    //TODO 将消息发送给当前在线的所有useSession
    public void sendMsgToAllOnlineUser(String appId, String userId, Object data) {
        List<UserSession> allUserSession = redisUserSessionUtils.getAllUserSession(appId, userId);
        for (UserSession userSession : allUserSession) {
            if (userSession.getConnectState() == ConnectStatusEnum.CONNECTING.getCode())
                sendMsg(JSONObject.toJSONString(data), userSession);
        }
    }

    //TODO 发送给指定用用户客户端
    public void sendMsgToTargetUser(String appId, String userId,Commend commend, ClientInfo clientInfo){
        UserSession singleUserSession = redisUserSessionUtils.getSingleUserSession(appId, userId, clientInfo.getClientType().toString()
                , clientInfo.getImei());
        sendPack(appId,commend,clientInfo.getClientType(),singleUserSession);
    }

    // TODO 发送数据给除了本端外的其它客户端
    public void sendMsgToOtherUserExpSelf(String appId, String userId,Object data,ClientInfo clientInfo){
        List<UserSession> allUserSession = redisUserSessionUtils.getAllUserSession(appId, userId);
        for (UserSession userSession : allUserSession) {
            if(!isSelf(userSession,clientInfo)){
                if (userSession.getConnectState() == ConnectStatusEnum.CONNECTING.getCode())
                    sendMsg(JSONObject.toJSONString(data), userSession);
            }
        }
    }

    */
/**
     * 同一个用户的不同客户端 比较clientType以及imei
     * @param userSession
     * @param clientInfo
     * @return
     *//*

    private boolean isSelf(UserSession userSession, ClientInfo clientInfo) {
        return Objects.equals(userSession.getClientType(),clientInfo.getClientType())
                &&Objects.equals(userSession.getImei(),clientInfo.getImei())
                &&Objects.equals(userSession.getAppId(),clientInfo.getAppId().toString());
    }

}
*/
